Thread: Finding common values in the rows of a vector [Need Help]

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I've also never heard of this. However, the math is based on using a scale factor. If you can figure out a suitable base-ten scale factor for your input, then you can do the math in integers with all of the significant digits, (as you've shown) and present the output in decimal format.

  2. #2
    Registered User
    Join Date
    Sep 2018
    Posts
    217
    By the way I ended up using this function (for future readers ):
    Code:
    int gcd(int a, int b) {
        return a == 0 ? b : gcd(b % a, a);
    }
    
    int find_gcd(vector <int> arr) {
        int result = arr[0];
        for (int i = 1; i < arr.size(); i++)
            result = gcd(arr[i], result);
        return result;
    }
    
    // example input:
        cout<< find_gcd({ 2, 4, 5 });
    It originally took an array as input, but vectors are better right?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D Array Problem - Finding each rows minimum value
    By Jordan Velez in forum C++ Programming
    Replies: 1
    Last Post: 05-11-2015, 01:04 PM
  2. Finding a common suffix
    By echo1525 in forum C Programming
    Replies: 3
    Last Post: 11-12-2012, 12:35 AM
  3. finding common numbers
    By BB89 in forum C Programming
    Replies: 14
    Last Post: 11-10-2009, 08:22 AM
  4. finding most common char in a string
    By scwizzo in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2007, 01:22 PM
  5. Finding the most common char
    By Mikro in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 09:00 AM

Tags for this Thread